﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Clients.aspx.cs" Inherits="Client_Revenue.Clients" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Clients List</h2>
    <div style="float: left; margin-right: 20px;">
        <asp:EntityDataSource ID="ClientsEntityDataSource" runat="server" ConnectionString="name=dominiumEntities"
            DefaultContainerName="dominiumEntities" EnableFlattening="False" EntitySetName="Clients" 
            EntityTypeFilter="Client"
           
            AutoGenerateOrderByClause="True" Where="" AutoGenerateWhereClause="True">
            <OrderByParameters>
                <asp:Parameter DefaultValue="ClientId" />
                <asp:Parameter Name="AddressId" />
            </OrderByParameters>
            
        </asp:EntityDataSource>
        <asp:GridView ID="ClientsGridView" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataSourceID="ClientsEntityDataSource" DataKeyNames="ClientId"
            OnSelectedIndexChanged="ClientsGridView_SelectedIndexChanged" 
            SelectedRowStyle-BackColor="LightGray" CssClass="datagrid"
            onrowediting="ClientsGridView_RowEditing" 
            onrowupdating="ClientsGridView_RowUpdating">
            <Columns><asp:CommandField ShowSelectButton="True" />
                <asp:TemplateField HeaderText="Client" SortExpression="ClientName">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("ClientName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <SelectedRowStyle BackColor="LightGray"></SelectedRowStyle>
        </asp:GridView>
    </div>
    <div>
        <asp:GridView ID="ContactPersonGridView" runat="server" AutoGenerateColumns="False"
            SelectedRowStyle-BackColor="LightGray" CssClass="datagrid"
            onrowcancelingedit="ContactPersonGridView_RowCancelingEdit" 
            onrowediting="ContactPersonGridView_RowEditing" DataKeyNames="PersonId" 
            onrowupdating="ContactPersonGridView_RowUpdating" 
            onpageindexchanging="ContactPersonGridView_PageIndexChanging">
            <EmptyDataTemplate>
                <p>
                    No Contact person found.</p>
            </EmptyDataTemplate>
            <SelectedRowStyle BackColor="LightGray"></SelectedRowStyle>
            <Columns>
             <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField HeaderText="Title" DataField="Title" SortExpression="Title" />
                <asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>' OnInit="txtFirstName_Init" Width="50"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField HeaderText="MidName" DataField="MidName" SortExpression="MidName" />
                <asp:TemplateField HeaderText="LastName" SortExpression="LastName">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>' Width="50"  OnInit="txtLastName_Init"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Phone" SortExpression="WorkPhone">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtWorkPhone" runat="server" Text='<%# Bind("WorkPhone") %>' Width="50"  OnInit="txtWorkPhone_Init"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("WorkPhone") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Mobile" SortExpression="MobilePhone">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtMobilePhone" OnInit="txtMobilePhone_Init" runat="server" Text='<%# Bind("MobilePhone") %>' Width="50"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("MobilePhone") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Email" SortExpression="EmailAddress">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtEmailAddress" OnInit="txtEmailAddress_Init" runat="server" Text='<%# Bind("EmailAddress") %>' Width="50"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%# Bind("EmailAddress") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="IsPrimaryContact" 
                    SortExpression="IsPrimaryContact">
                    <EditItemTemplate>
                        <asp:CheckBox ID="ckIsPrimaryContact" runat="server" Text='<%# Bind("IsPrimaryContact") %>'/>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="ckIsPrimaryContact" runat="server" Checked='<%# Bind("IsPrimaryContact") %>'/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="SendCard" SortExpression="SendCard">
                    <EditItemTemplate>
                         <asp:CheckBox ID="ckSendCard" runat="server" Text='<%# Bind("SendCard") %>'/>
                     </EditItemTemplate>
                    <ItemTemplate> 
                       <asp:CheckBox ID="ckSendCard" runat="server" Checked='<%# Bind("SendCard") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            
            </Columns>
        </asp:GridView>

        <h3>
            Selected Client's Address</h3>
        <asp:EntityDataSource ID="ClientAddressEntityDataSource" runat="server" EnableFlattening="False"
            EntitySetName="Addresses" ConnectionString="name=dominiumEntities" DefaultContainerName="dominiumEntities"
            Select="it.[AddressId], it.[Line1], it.[Line2], it.[Line3], it.[City], it.[State], it.[Zip], it.[URL]"
            Where="it.[AddressId] = @AddressId" AutoGenerateOrderByClause="True" 
            >
            <OrderByParameters>
                <asp:Parameter DefaultValue="AddressId" />
            </OrderByParameters>
            <WhereParameters>
                <asp:ControlParameter ControlID="ClientsGridView" Type="Int32" Name="AddressId" PropertyName="SelectedValue" />
            </WhereParameters>
        </asp:EntityDataSource>
        <asp:GridView ID="ClientAddressGridView" runat="server" DataSourceID="ClientAddressEntityDataSource" CssClass="datagrid"
            AutoGenerateColumns="False" SelectedRowStyle-BackColor="LightGray" 
            DataKeyNames="AddressId" AllowPaging="True">
            <EmptyDataTemplate>
                <p>
                    No Address found.</p>
            </EmptyDataTemplate>
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:CommandField ShowEditButton="True" />
                <asp:TemplateField HeaderText="Line 1" SortExpression="Line1">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtLine1" runat="server" Width="200" Text='<%# Bind("Line1") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Line1") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Line 2" SortExpression="Line2">
                    <EditItemTemplate>
                        <asp:TextBox ID="txtLine2" runat="server" Width="50px" Text='<%# Eval("Line2") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Line2") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Line 3" SortExpression="Line3">
                    <EditItemTemplate>
                        <asp:TextBox ID="Label3" runat="server" Width="30px" Text='<%# Bind("Line3") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("Line3") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="City" SortExpression="City">
                    <EditItemTemplate>
                        <asp:TextBox ID="Label4" runat="server" Text='<%# Eval("City") %>' Width="75"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("City") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="State" SortExpression="State">
                    <EditItemTemplate>
                        <asp:TextBox ID="Label5" runat="server" Text='<%# Eval("State") %>' Width="20"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%# Bind("State") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Zip" SortExpression="Zip">
                    <EditItemTemplate>
                        <asp:TextBox ID="Label6" runat="server" Text='<%# Eval("Zip") %>' Width="40"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label6" runat="server" Text='<%# Bind("Zip") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="URL" SortExpression="URL">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox" runat="server" Text='<%# Eval("URL") %>' Width="100"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label7" runat="server" Text='<%# Bind("URL") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <SelectedRowStyle BackColor="LightGray"></SelectedRowStyle>
        </asp:GridView>
    </div>
</asp:Content>
